<template>
  <!-- 收取加速折旧费-->
  <view class="normal-login-container">

    <view class="item-wrap" style="margin-bottom: 0">
      <view class="lineBottom10">
        <uni-section title="收取加速折旧费" type="line"/>
      </view>

      <view style="margin: 8rpx 20rpx 8rpx 20rpx">
        <uni-forms ref="ruleForm" :rules="rules" :label-position="boole ? 'top' : 'left'" :model="ruleForm"
                   labelWidth="auto">

          <uni-forms-item label="加速折旧费方案:">
            <zxz-uni-data-select v-if="boole" v-model="ruleForm.depreciationPlanId" :localdata="depreciationList"
                                 dataKey="planName" dataValue="id"
                                 :disabled="!ruleForm.vehicleAssessmentPrice"
                                 @change="handleChangeDepreciation"
                                 placeholder="请选择加速折旧费方案"
                                 :clear="true" filterable/>
            <text v-else> {{ ruleForm.depreciationPlan || '-' }}</text>
          </uni-forms-item>


          <uni-forms-item label="加速折旧费金额:">
            <uni-easyinput v-if="boole" v-model="ruleForm.depreciationPrice"
                           disabled
                           @blur="blurAmount('depreciationPrice')"
                           placeholder="请输入加速折旧费金额"/>
            <text v-else> {{ ruleForm.depreciationPrice || '-' }}</text>
          </uni-forms-item>


        </uni-forms>
      </view>
    </view>
  </view>
</template>

<script>
import {getList} from "@/api/maintain/maintainList";
import {toNumberSub, toNumberRide, toNumberExcept} from '@/pages/quota/libs/utils.js';

export default {
  name: 'accelerated',//收取加速折旧费
  components: {},
  props: {
    value: {
      type: Object,
      default: {},
    },
    boole: {
      type: Boolean,
      default: true,
    },
    depreciationList:{
      type: Array,
      default: [],
    }
  },
  computed: {
    ruleForm: {
      get() {
        let that = this;
        const proxy = new Proxy(that.value, {
          get(target, key) {
            return Reflect.get(target, key);
          },
          set(target, key, value) {
            that.$emit("input", {...target, [key]: value});
            return true;
          },
        });
        return proxy;
      },
    },
    handleLabel() {
      return function (arr, type) {
        let name = "";
        arr.map((v) => {
          if (type == v.value) {
            name = v.label;
          }
        });
        return name;
      };
    },
  },
  data() {
    return {
      
    };
  },
  created() {
  },
  mounted() {
    
  },
  methods: {
    

    handleChangeDepreciation(val) {
      if (val) {
        console.log(val)
        this.value.depreciationPlanId = this.ruleForm.depreciationPlanId = val.id;
        this.value.depreciationPlan = this.ruleForm.depreciationPlan = val.planName
        let a = toNumberSub(Number(this.ruleForm.vehicleAssessmentPrice || 0), Number(val.deductionAmount || 0))
        let b = toNumberRide(a, Number(val.scale || 0))
        let c = toNumberExcept(b, 100)
        this.ruleForm.depreciationPrice = c > 0 ? c : "";
        this.$set(this.value, "depreciationPlan", val.planName);
        this.$set(
            this.value,
            "depreciationPrice",
            this.ruleForm.depreciationPrice
        );
      }
    },


    handleEffect() {
      return new Promise((resolve, reject) => {
        this.$refs.ruleForm
            .validate()
            .then((res) => {
              resolve();
            })
            .catch((err) => {
              let key = ".flex-col" + ">>>" + "." + err[0].key;
              reject(key);
            });
      });
    },
  },
};
</script>

<style scoped lang=""></style>


